﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Reflection;
using System.Windows.Forms;
using HML.Design;

namespace HML
{
    /// <summary>
    /// 图片幻灯片控件
    /// </summary>
    [Description("图片幻灯片控件")]
    [DefaultProperty("Images")]
    [DefaultEvent("IndexChanged")]
    [TypeConverter(typeof(ImageSlideConverter))]
    [Designer(typeof(ImageSlideDesigner))]
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(ImageSlide), "Controls.ImageSlide.Resources.ImageSlide.bmp")]
    public class ImageSlide : MainThreadAnimationControl, ISkinObject
    {
        #region 主题

        private SkinObjectXmlMetadata skinObjectXmlMetadata = null;
        /// <summary>
        /// 主题对象在主题文件信息
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual SkinObjectXmlMetadata SkinObjectXmlMetadata
        {
            get
            {
                if (this.skinObjectXmlMetadata == null)
                    this.skinObjectXmlMetadata = new SkinObjectXmlMetadata(Assembly.GetAssembly(typeof(ImageSlide)).GetName().Name, typeof(ImageSlide).Name);

                return this.skinObjectXmlMetadata;
            }
        }

        private SkinController skinController = null;
        /// <summary>
        /// 主题控制器
        /// </summary>
        [Description("主题控制器")]
        [Category("杂项")]
        [PropertyOrder(-360)]
        [DefaultValue(null)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinController SkinController
        {
            get { return this.skinController; }
            set
            {
                if (this.skinController == value)
                    return;

                if (this.skinController != null)
                    this.skinController.RemoveSkinObject(this);

                this.skinController = value;

                if (this.skinController != null)
                    this.skinController.AddSkinObject(this);
            }
        }

        private SkinEnabledState skinEnabled= SkinEnabledState.Auto;
        /// <summary>
        /// 主题是否启用
        /// </summary>
        [Description("主题是否启用")]
        [Category("杂项")]
        [PropertyOrder(-300)]
        [DefaultValue(SkinEnabledState.Auto)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinEnabledState SkinEnabled
        {
            get { return this.skinEnabled; }
            set
            {
                if (this.skinEnabled == value)
                    return;

                this.skinEnabled = value;
                this.OnSkinChanged();
            }
        }

        private SkinStyle skinStyle = SkinStyle.Normal;
        /// <summary>
        /// 主题风格
        /// </summary>
        [Description("主题风格")]
        [Category("杂项")]
        [PropertyOrder(-260)]
        [DefaultValue(SkinStyle.Normal)]
        [RefreshProperties(RefreshProperties.All)]
        public virtual SkinStyle SkinStyle
        {
            get { return this.skinStyle; }
            set
            {
                if (this.skinStyle == value)
                    return;

                this.skinStyle = value;
                this.OnSkinChanged();
            }
        }

        private StyleAppearanceObject stateAppearance;
        /// <summary>
        /// 风格外观
        /// </summary>
        [Description("风格外观")]
        [Category("杂项")]
        [PropertyOrder(-200)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public StyleAppearanceObject StyleAppearance
        {
            get
            {
                if (this.stateAppearance == null)
                    this.stateAppearance = new StyleAppearanceObject(this, null);
                return this.stateAppearance;
            }
        }

        /// <summary>
        /// 主题已更改
        /// </summary>
        public virtual void OnSkinChanged()
        {
            SkinManager.SyncSkinValueToProperty(this);
            this.Invalidate();
        }

        private ISkinObject followSkinObject = null;
        /// <summary>
        /// 主题设置跟随指定主题对象（自己的设置不再生效，提供给代码使用）
        /// </summary>
        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [Localizable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public virtual ISkinObject FollowSkinObject
        {
            get { return this.followSkinObject; }
            set
            {
                if (this.followSkinObject == value)
                    return;

                this.followSkinObject = value;
                this.OnSkinChanged();
            }
        }

        public virtual bool GetSkinObjectSkinStateCore()
        {
            return SkinManager.GetSkinObjectSkinState(this.FollowSkinObject ?? this);
        }

        void ISkinObject.InitializeInvalidate()
        {
            this.InitializeElement();
            this.Invalidate();
        }

        void ISkinObject.Invalidate()
        {
            this.Invalidate();
        }

        #endregion

        #region 新增事件

        private static readonly object EventIndexChanged = new object();
        /// <summary>
        /// 图片轮播索引更改事件
        /// </summary>
        [Description("图片轮播索引更改事件")]
        public event EventHandler IndexChanged
        {
            add { Events.AddHandler(EventIndexChanged, value); }
            remove { Events.RemoveHandler(EventIndexChanged, value); }
        }

        #endregion

        #region 停用事件

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler PaddingChanged
        {
            add { base.PaddingChanged += value; }
            remove { base.PaddingChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TabIndexChanged
        {
            add { base.TabIndexChanged += value; }
            remove { base.TabIndexChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TabStopChanged
        {
            add { base.TabStopChanged += value; }
            remove { base.TabStopChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler TextChanged
        {
            add { base.TextChanged += value; }
            remove { base.TextChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler RightToLeftChanged
        {
            add { base.RightToLeftChanged += value; }
            remove { base.RightToLeftChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ImeModeChanged
        {
            add { base.ImeModeChanged += value; }
            remove { base.ImeModeChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageChanged
        {
            add { base.BackgroundImageChanged += value; }
            remove { base.BackgroundImageChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackgroundImageLayoutChanged
        {
            add { base.BackgroundImageLayoutChanged += value; }
            remove { base.BackgroundImageLayoutChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler BackColorChanged
        {
            add { base.BackColorChanged += value; }
            remove { base.BackColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler ForeColorChanged
        {
            add { base.ForeColorChanged += value; }
            remove { base.ForeColorChanged -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler Click
        {
            add { base.Click += value; }
            remove { base.Click -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event EventHandler DoubleClick
        {
            add { base.DoubleClick += value; }
            remove { base.DoubleClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseClick
        {
            add { base.MouseClick += value; }
            remove { base.MouseClick -= value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new event MouseEventHandler MouseDoubleClick
        {
            add { base.MouseDoubleClick += value; }
            remove { base.MouseDoubleClick -= value; }
        }

        #endregion

        #region 新增属性

        private ImageSlideOrientation orientation = ImageSlideOrientation.RightToLeft;
        /// <summary>
        ///图片滑动播放方向 
        /// </summary>
        [Description("图片滑动播放方向")]
        [Category("杂项")]
        [PropertyOrder(-199)]
        [DefaultValue(ImageSlideOrientation.RightToLeft)]
        public ImageSlideOrientation Orientation
        {
            get { return this.orientation; }
            set
            {
                if (this.orientation == value)
                    return;

                this.orientation = value;
                this.current_orientation = this.orientation;
                this.SetBoundsCore(this.Location.X, this.Location.Y, this.Width, this.Height, BoundsSpecified.Size);
                this.UpdateImageFrameInfo();
                this.Invalidate();
            }
        }

        private bool borderVisible = true;
        /// <summary>
        ///是否显示边框
        /// </summary>
        [Description("是否显示边框")]
        [Category("杂项")]
        [PropertyOrder(-198)]
        [DefaultValue(true)]
        public bool BorderVisible
        {
            get { return this.borderVisible; }
            set
            {
                if (this.borderVisible == value)
                    return;

                this.borderVisible = value;
                this.Invalidate();
            }
        }

        private TitleBarObject titleBar;
        /// <summary>
        /// 标题栏
        /// </summary>
        [Description("标题栏")]
        [Category("杂项")]
        [PropertyOrder(-194)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public TitleBarObject TitleBar
        {
            get
            {
                if (this.titleBar == null)
                    this.titleBar = new TitleBarObject(this);
                return this.titleBar;
            }
        }

        private NavigationBarObject navigationBar;
        /// <summary>
        /// 导航栏
        /// </summary>
        [Description("导航栏")]
        [Category("杂项")]
        [PropertyOrder(-192)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public NavigationBarObject NavigationBar
        {
            get
            {
                if (this.navigationBar == null)
                    this.navigationBar = new NavigationBarObject(this);
                return this.navigationBar;
            }
        }

        private LegendsBarObject legendsBar;
        /// <summary>
        /// 图例栏
        /// </summary>
        [Description("图例栏")]
        [Category("杂项")]
        [PropertyOrder(-190)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public LegendsBarObject LegendsBar
        {
            get
            {
                if (this.legendsBar == null)
                    this.legendsBar = new LegendsBarObject(this);
                return this.legendsBar;
            }
        }

        private Size frameSize = new Size(200, 100);
        /// <summary>
        ///图片框Size
        /// </summary>
        [Description("图片框Size")]
        [Category("杂项")]
        [PropertyOrder(-188)]
        [DefaultValue(typeof(Size), "200,100")]
        public Size FrameSize
        {
            get { return this.frameSize; }
            set
            {
                if (value.Width < 1)
                {
                    value.Width = 1;
                }
                if (value.Height < 1)
                {
                    value.Height = 1;
                }
                if (this.frameSize == value)
                    return;

                this.frameSize = value;
                this.SetBoundsCore(this.Location.X, this.Location.Y, this.Width, this.Height, BoundsSpecified.Size);
                this.UpdateImageFrameInfo();
                this.Invalidate();
            }
        }

        private int frameAmount = 1;
        /// <summary>
        ///显示区要显示的图片框数量
        /// </summary>
        [Description("显示区要显示的图片框数量")]
        [Category("杂项")]
        [PropertyOrder(-186)]
        [DefaultValue(1)]
        public int FrameAmount
        {
            get { return this.frameAmount; }
            set
            {
                if (this.frameAmount == value || value < 1)
                    return;

                this.frameAmount = value;
                this.SetBoundsCore(this.Location.X, this.Location.Y, this.Width, this.Height, BoundsSpecified.Size);
                this.LoadImageFrame();
                this.UpdateImageFrameInfo();
                this.Invalidate();
            }
        }

        private bool autoSuspend = false;
        /// <summary>
        /// 鼠标进入时是否停止自动切换
        /// </summary>
        [Description("鼠标进入时是否停止自动切换")]
        [Category("杂项")]
        [PropertyOrder(-184)]
        [DefaultValue(false)]
        public bool AutoSuspend
        {
            get { return this.autoSuspend; }
            set
            {
                if (this.autoSuspend == value)
                    return;

                this.autoSuspend = value;
            }
        }

        private double frameSliderTime = 500d;
        /// <summary>
        /// 图片框滑动总时间(单位毫秒)
        /// </summary>
        [Description("图片框滑动总时间(单位毫秒)")]
        [Category("杂项")]
        [PropertyOrder(-180)]
        [DefaultValue(500d)]
        public double FrameSliderTime
        {
            get { return this.frameSliderTime; }
            set
            {
                if (this.frameSliderTime == value || value < 0)
                    return;

                this.frameSliderTime = value;
            }
        }

        private int frameIntervalTime = 1000;
        /// <summary>
        /// 图片框停留间隔时间(单位毫秒)
        /// </summary>
        [Description("图片框停留间隔时间(单位毫秒)")]
        [Category("杂项")]
        [PropertyOrder(-178)]
        [DefaultValue(1000)]
        public int FrameIntervalTime
        {
            get { return this.frameIntervalTime; }
            set
            {
                if (this.frameIntervalTime == value || value < 0)
                    return;
                this.frameIntervalTime = value;
            }
        }

        private ImageSlideImageItemCollection itemCollection;
        /// <summary>
        /// 图片选项集合
        /// </summary>
        [Description("图片选项集合")]
        [Category("杂项")]
        [PropertyOrder(-176)]
        [DefaultValue(null)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public ImageSlideImageItemCollection Items
        {
            get
            {
                if (this.itemCollection == null)
                    this.itemCollection = new ImageSlideImageItemCollection(this);
                return this.itemCollection;
            }
        }

        private int index = 0;
        /// <summary>
        ///图片开始的索引（负向第一个为最左边、正向第一个为最右边）
        /// </summary>
        [Description("图片开始的索引（负向第一个为最左边、正向第一个为最右边）")]
        [Category("杂项")]
        [PropertyOrder(-174)]
        [Browsable(false)]
        [Localizable(false)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public int Index
        {
            get
            {
                if (this.Items.Count < 1)
                    return -1;

                return this.index;
            }
            set
            {
                if (this.index == value || value < 0)
                    return;

                if (animationStatus == AnimationStatus.Await || this.animationStatus == AnimationStatus.Slide)
                {
                    this.animationStatus = AnimationStatus.Await;
                }
                this.intervalTimeValue = 0;
                this.slideTimeValue = 0;
                this.current_distanceprogress = 1;
                this.index = value;

                this.RestoreOrientation();
                this.UpdateImageFrameInfo();

                if (!this.DesignMode)
                {
                    this.OnIndexChanged(EventArgs.Empty);
                }

                this.Invalidate();
            }
        }

        #endregion

        #region 重写属性

        protected override Size DefaultSize
        {
            get { return new Size(400, 200); }
        }

        protected override ImeMode DefaultImeMode
        {
            get { return ImeMode.Disable; }
        }

        #endregion

        #region 停用属性

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new Padding Padding
        {
            get { return base.Padding; }
            set { base.Padding = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new int TabIndex
        {
            get { return base.TabIndex; }
            set { base.TabIndex = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public new bool TabStop
        {
            get { return base.TabStop; }
            set { base.TabStop = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override string Text
        {
            get { return base.Text; }
            set { base.Text = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public override RightToLeft RightToLeft
        {
            get { return base.RightToLeft; }
            set { base.RightToLeft = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        public new ImeMode ImeMode
        {
            get { return base.ImeMode; }
            set { base.ImeMode = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Image BackgroundImage
        {
            get { return base.BackgroundImage; }
            set { base.BackgroundImage = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override ImageLayout BackgroundImageLayout
        {
            get { return base.BackgroundImageLayout; }
            set { base.BackgroundImageLayout = value; }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color BackColor
        {
            get { return this.StyleAppearance.BackColor; }
            set { }
        }

        [Browsable(false)]
        [EditorBrowsable(EditorBrowsableState.Never)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public override Color ForeColor
        {
            get { return this.StyleAppearance.TitleBar.TextColor; }
            set { }
        }

        #endregion

        #region 字段

        /// <summary>
        /// 当前鼠标已按下的对象
        /// </summary>
        private object mousedownobject = null;

        /// <summary>
        /// 图片框集合
        /// </summary>
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        private List<ImageFrame> imageFrames = new List<ImageFrame>();

        /// <summary>
        /// 滑动动画已使用的时间累计
        /// </summary>
        private double slideTimeValue = 0;

        /// <summary>
        /// 滑动动画的间隔时间累计
        /// </summary>
        private int intervalTimeValue = 0;

        /// <summary>
        /// 是否暂停滑动动画的间隔时间累计
        /// </summary>
        private bool isSuspendIntervalTimeValue = false;

        /// <summary>
        /// 当前滑动方向
        /// </summary>
        private ImageSlideOrientation current_orientation = ImageSlideOrientation.RightToLeft;

        /// <summary>
        /// 图片框当前滑动进度
        /// </summary>
        private double current_distanceprogress = 0;

        /// <summary>
        /// 当前动画状态
        /// </summary>
        private AnimationStatus animationStatus = AnimationStatus.Stop;

        /// <summary>
        /// 控件是否处于失效状态
        /// </summary>
        private bool isDisabled = false;

        /// <summary>
        /// 是否在Stop状态下利用导航栏进行一次切换
        /// </summary>
        private bool isOnceSlide = false;

        #endregion

        public ImageSlide()
        {
            SetStyle(ControlStyles.UserPaint, true);
            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.ResizeRedraw, true);
            SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            SetStyle(ControlStyles.StandardClick, false);//自定义单击事件逻辑
            SetStyle(ControlStyles.StandardDoubleClick, false);//停用双加事件

            this.SuspendLayout();
            this.TabStop = false;
            this.NavigationBar.CurrentVisible = this.NavigationBar.Visible == ImageSlideNavigationBarVisibility.Always ? true : false;
            this.InitializeElement();
            this.LoadImageFrame();
            this.OnSkinChanged();
            this.ResumeLayout();
        }

        #region 重写

        protected override void OnScaleDpiChangedInitialize()
        {
            this.SetBoundsCore(this.Location.X, this.Location.Y, this.Width, this.Height, BoundsSpecified.Size);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            Graphics g = e.Graphics;

            Size scale_frameSize = new Size((int)Math.Ceiling(this.FrameSize.Width * this.ScaleDpi), (int)Math.Ceiling(this.FrameSize.Height * this.ScaleDpi));
            TBPadding scale_titleBarPadding = new TBPadding((int)Math.Ceiling(this.TitleBar.TBPadding.Top * this.ScaleDpi), (int)Math.Ceiling(this.TitleBar.TBPadding.Bottom * this.ScaleDpi));

            Pen border_pen = null;
            SolidBrush back_sb = null;
            SolidBrush fore_sb = null;

            if (this.Items.Count > 0)
            {
                // 图片框
                for (int i = 0; i < this.imageFrames.Count; i++)
                {
                    int index = this.imageFrames[i].SourceImageIndex;
                    Rectangle frame_rect = Rectangle.Empty;
                    int current_distance = (int)(this.GetImageFrameSlideDirection() * (1 - (this.animationStatus == AnimationStatus.Slide ? this.current_distanceprogress : 1)));
                    if (this.IsHorizonta(this.Orientation))
                    {
                        frame_rect = new Rectangle(this.ClientRectangle.X - scale_frameSize.Width + i * scale_frameSize.Width + current_distance, this.ClientRectangle.Y, scale_frameSize.Width, scale_frameSize.Height);
                    }
                    else
                    {
                        frame_rect = new Rectangle(this.ClientRectangle.X, this.ClientRectangle.Y - scale_frameSize.Height + i * scale_frameSize.Height + current_distance, scale_frameSize.Width, scale_frameSize.Height);
                    }

                    // 图片
                    if (this.Items[index].Image != null)
                    {
                        Image image = (scale_frameSize == this.Items[index].Image.Size) ? this.Items[index].Image : this.imageFrames[i].ScaleImage;
                        if (image != null)
                        {
                            g.DrawImageUnscaled(image, frame_rect.Location);
                        }
                    }

                    // 图片标题
                    if (this.TitleBar.Visible)
                    {
                        if (border_pen == null)
                            border_pen = new Pen(this.StyleAppearance.TitleBar.BorderColor);
                        else
                            border_pen.Color = this.StyleAppearance.TitleBar.BorderColor;

                        if (back_sb == null)
                            back_sb = new SolidBrush(this.StyleAppearance.TitleBar.BackColor);
                        else
                            back_sb.Color = this.StyleAppearance.TitleBar.BackColor;

                        if (fore_sb == null)
                            fore_sb = new SolidBrush(this.StyleAppearance.TitleBar.TextColor);
                        else
                            fore_sb.Color = this.StyleAppearance.TitleBar.TextColor;

                        NativeMethods.TEXTMETRIC font_metrics = ControlHelper.GetFontMetrics(this.Handle, this.Font);
                        Rectangle title_rect = new Rectangle(frame_rect.X, frame_rect.Y, frame_rect.Width, scale_titleBarPadding.Top + font_metrics.GetFontRealHeight() + scale_titleBarPadding.Bottom);
                        g.FillRectangle(back_sb, title_rect);
                        string title = this.Items[index].Text;
                        if (!String.IsNullOrWhiteSpace(title))
                        {
                            Size text_size = new Size((int)Math.Ceiling(g.MeasureString(title, this.Font, int.MaxValue, StringFormat.GenericTypographic).Width), font_metrics.GetFontRealHeight());
                            g.DrawString(title, this.Font, fore_sb, new Point(Math.Max(title_rect.X, title_rect.X + (title_rect.Width - text_size.Width) / 2), title_rect.Y + scale_titleBarPadding.Top), StringFormat.GenericTypographic);
                        }
                        g.DrawLine(border_pen, new PointF(title_rect.X + 1, title_rect.Bottom), new PointF(title_rect.Right - 1, title_rect.Bottom));
                    }

                }

                //导航栏
                if (this.NavigationBar.Visible == ImageSlideNavigationBarVisibility.Always || (this.NavigationBar.Visible == ImageSlideNavigationBarVisibility.Auto && this.NavigationBar.CurrentVisible))
                {
                    if (back_sb == null)
                        back_sb = new SolidBrush(Color.White);
                    if (fore_sb == null)
                        fore_sb = new SolidBrush(Color.White);
                    if (border_pen == null)
                        border_pen = new Pen(Color.White);

                    back_sb.Color = this.NavigationBar.PrevButtonIsMouseEnter ? this.StyleAppearance.NavigationBar.Enter.BackColor : this.StyleAppearance.NavigationBar.Normal.BackColor;
                    g.FillRectangle(back_sb, this.NavigationBar.PrevButton_Rectangle);
                    back_sb.Color = this.NavigationBar.NextButtonIsMouseEnter ? this.StyleAppearance.NavigationBar.Enter.BackColor : this.StyleAppearance.NavigationBar.Normal.BackColor;
                    g.FillRectangle(back_sb, this.NavigationBar.NextButton_Rectangle);

                    Pen line_pen = new Pen(Color.White, this.NavigationBar.ButtonLineThickness) { StartCap = LineCap.Round, EndCap = LineCap.Round };
                    g.SmoothingMode = SmoothingMode.AntiAlias;
                    line_pen.Color = this.NavigationBar.PrevButtonIsMouseEnter ? this.StyleAppearance.NavigationBar.Enter.ForeColor : this.StyleAppearance.NavigationBar.Normal.ForeColor;
                    g.DrawLines(line_pen, this.NavigationBar.PrevButton_LinePoint);
                    line_pen.Color = this.NavigationBar.NextButtonIsMouseEnter ? this.StyleAppearance.NavigationBar.Enter.ForeColor : this.StyleAppearance.NavigationBar.Normal.ForeColor;
                    g.DrawLines(line_pen, this.NavigationBar.NextButton_LinePoint);
                    g.SmoothingMode = SmoothingMode.Default;
                    line_pen.Dispose();

                    border_pen.Width = 1;
                    border_pen.Color = this.NavigationBar.PrevButtonIsMouseEnter ? this.StyleAppearance.NavigationBar.Enter.BorderColor : this.StyleAppearance.NavigationBar.Normal.BorderColor;
                    g.DrawRectangle(border_pen, this.NavigationBar.PrevButton_Rectangle.X, this.NavigationBar.PrevButton_Rectangle.Y, this.NavigationBar.PrevButton_Rectangle.Width - 1, this.NavigationBar.PrevButton_Rectangle.Height - 1);
                    border_pen.Color = this.NavigationBar.NextButtonIsMouseEnter ? this.StyleAppearance.NavigationBar.Enter.BorderColor : this.StyleAppearance.NavigationBar.Normal.BorderColor;
                    g.DrawRectangle(border_pen, this.NavigationBar.NextButton_Rectangle.X, this.NavigationBar.NextButton_Rectangle.Y, this.NavigationBar.NextButton_Rectangle.Width - 1, this.NavigationBar.NextButton_Rectangle.Height - 1);

                }

                // 图例栏
                if (this.LegendsBar.Visible)
                {
                    int scale_legendSize = (int)(this.LegendsBar.Size * this.ScaleDpi);
                    float scale_legendSpace = scale_legendSize / 2f;

                    for (int i = 0; i < this.Items.Count; i++)
                    {
                        bool iscurrent = (i == (this.IsNegative(this.Orientation) ? this.Index : Math.Abs(this.Items.Count - 1 - this.Index)));
                        Color border_color = iscurrent ? this.StyleAppearance.LegendsBar.Current.BorderColor : this.StyleAppearance.LegendsBar.Normal.BorderColor;
                        Color back_color = iscurrent ? this.StyleAppearance.LegendsBar.Current.BackColor : this.StyleAppearance.LegendsBar.Normal.BackColor;

                        if (back_sb == null)
                            back_sb = new SolidBrush(back_color);
                        else
                            back_sb.Color = back_color;

                        if (border_pen == null)
                            border_pen = new Pen(border_color);
                        else
                            border_pen.Color = border_color;


                        RectangleF legend_rectf = RectangleF.Empty;
                        if (this.IsHorizonta(this.current_orientation))
                        {
                            float start_x = this.ClientRectangle.X + (this.ClientRectangle.Width - ((scale_legendSize + scale_legendSpace) * this.Items.Count - scale_legendSpace)) / 2f;
                            legend_rectf = new RectangleF(start_x + i * scale_legendSize + (i - 1) * scale_legendSpace, this.ClientRectangle.Bottom - scale_legendSize * 2, scale_legendSize, scale_legendSize);
                        }
                        else
                        {
                            float start_y = this.ClientRectangle.Y + (this.ClientRectangle.Height - ((scale_legendSize + scale_legendSpace) * this.Items.Count - scale_legendSpace)) / 2f;
                            legend_rectf = new RectangleF(this.ClientRectangle.Right - scale_legendSize * 2, start_y + i * scale_legendSize + (i - 1) * scale_legendSpace, scale_legendSize, scale_legendSize);
                        }
                        g.FillRectangle(back_sb, legend_rectf);
                        g.DrawRectangle(border_pen, legend_rectf.X, legend_rectf.Y, legend_rectf.Width, legend_rectf.Height);

                    }
                }

            }

            //边框
            if (this.BorderVisible)
            {
                if (border_pen == null)
                    border_pen = new Pen(this.StyleAppearance.BorderColor);
                else
                    border_pen.Color = this.StyleAppearance.BorderColor;

                g.DrawRectangle(border_pen, this.ClientRectangle.X, this.ClientRectangle.Y, this.ClientRectangle.Width - 1, this.ClientRectangle.Height - 1);
            }

            if (border_pen != null)
                border_pen.Dispose();
            if (back_sb != null)
                back_sb.Dispose();
            if (fore_sb != null)
                fore_sb.Dispose();
        }

        protected override void OnLostFocus(EventArgs e)
        {
            base.OnLostFocus(e);

            this.mousedownobject = null;
            this.Invalidate();
        }

        protected override void OnEnabledChanged(EventArgs e)
        {
            base.OnEnabledChanged(e);

            if (this.DesignMode)
                return;

            this.AutoUpdateDisabledStatus();
        }

        protected override void OnVisibleChanged(EventArgs e)
        {
            base.OnVisibleChanged(e);

            if (this.DesignMode)
                return;

            this.AutoUpdateDisabledStatus();
        }

        protected override void OnParentChanged(EventArgs e)
        {
            base.OnParentChanged(e);

            if (this.DesignMode)
                return;

            this.AutoUpdateDisabledStatus();
        }

        protected override void OnMouseEnter(EventArgs e)
        {
            base.OnMouseEnter(e);

            // 暂停播放间隔定时器
            if (this.AutoSuspend)
            {
                this.isSuspendIntervalTimeValue = true;
            }

            // 导航栏
            if (this.NavigationBar.Visible == ImageSlideNavigationBarVisibility.Auto)
            {
                this.NavigationBar.CurrentVisible = true;
                this.Invalidate();
            }

        }

        protected override void OnMouseLeave(EventArgs e)
        {
            base.OnMouseLeave(e);

            // 恢复播放间隔定时器
            this.isSuspendIntervalTimeValue = false;

            // 导航栏
            if (this.NavigationBar.Visible == ImageSlideNavigationBarVisibility.Auto)
            {
                this.NavigationBar.CurrentVisible = false;
            }
            this.NavigationBar.PrevButtonIsMouseEnter = false;
            this.NavigationBar.NextButtonIsMouseEnter = false;

            this.Invalidate();
        }

        protected override void OnMouseDown(MouseEventArgs e)
        {
            if (!this.Focused)
            {
                this.Focus();
            }

            if (e.Button == MouseButtons.Left)
            {
                bool isfind = false;

                if (this.NavigationBar.Visible != ImageSlideNavigationBarVisibility.Never)
                {
                    if (this.NavigationBar.PrevButton_Rectangle.Contains(e.Location))
                    {
                        isfind = true;
                        this.mousedownobject = this.NavigationBar.PrevButton_Object;
                        goto result;
                    }
                    if (this.NavigationBar.NextButton_Rectangle.Contains(e.Location))
                    {
                        isfind = true;
                        this.mousedownobject = this.NavigationBar.NextButton_Object;
                        goto result;
                    }
                }

            result:
                if (isfind == false)
                {
                    this.mousedownobject = null;
                }
            }

            base.OnMouseDown(e);
        }

        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                if (this.mousedownobject != null)
                {
                    if (this.NavigationBar.Visible != ImageSlideNavigationBarVisibility.Never)
                    {
                        if (this.mousedownobject == this.NavigationBar.PrevButton_Object && this.NavigationBar.PrevButton_Rectangle.Contains(e.Location))
                        {
                            if (this.animationStatus == AnimationStatus.Stop)
                            {
                                this.isOnceSlide = true;
                                MainThreadAnimationControl.AnimationStart(this);
                                this.animationStatus = AnimationStatus.Await;
                            }

                            if (this.animationStatus == AnimationStatus.Await)
                            {
                                if (this.Orientation == ImageSlideOrientation.LeftToRight)
                                {
                                    this.current_orientation = ImageSlideOrientation.RightToLeft;
                                }
                                else if (this.Orientation == ImageSlideOrientation.TopToBottom)
                                {
                                    this.current_orientation = ImageSlideOrientation.BottomToTop;
                                }

                                this.SwitchNext();
                            }
                        }
                        else if (this.mousedownobject == this.NavigationBar.NextButton_Object && this.NavigationBar.NextButton_Rectangle.Contains(e.Location))
                        {
                            if (this.animationStatus == AnimationStatus.Stop)
                            {
                                this.isOnceSlide = true;
                                MainThreadAnimationControl.AnimationStart(this);
                                this.animationStatus = AnimationStatus.Await;
                            }

                            if (this.animationStatus == AnimationStatus.Await)
                            {
                                if (this.Orientation == ImageSlideOrientation.RightToLeft)
                                {
                                    this.current_orientation = ImageSlideOrientation.LeftToRight;
                                }
                                else if (this.Orientation == ImageSlideOrientation.BottomToTop)
                                {
                                    this.current_orientation = ImageSlideOrientation.TopToBottom;
                                }

                                this.SwitchNext();
                            }
                        }
                    }

                    bool isReset = false;

                    bool pre_status = this.NavigationBar.PrevButton_Rectangle.Contains(e.Location);
                    if (this.NavigationBar.PrevButtonIsMouseEnter != pre_status)
                    {
                        this.NavigationBar.PrevButtonIsMouseEnter = pre_status;
                        isReset = true;
                    }

                    bool next_status = this.NavigationBar.NextButton_Rectangle.Contains(e.Location);
                    if (this.NavigationBar.NextButtonIsMouseEnter != next_status)
                    {
                        this.NavigationBar.NextButtonIsMouseEnter = next_status;
                        isReset = true;
                    }

                    if (isReset)
                    {
                        this.Invalidate();
                    }
                }
            }
            this.mousedownobject = null;

            base.OnMouseUp(e);

        }

        protected override void OnMouseMove(MouseEventArgs e)
        {
            // 导航栏
            if (this.mousedownobject == null && this.NavigationBar.Visible != ImageSlideNavigationBarVisibility.Never)
            {
                bool isReset = false;

                if (this.NavigationBar.Visible == ImageSlideNavigationBarVisibility.Auto && this.NavigationBar.CurrentVisible == false)
                {
                    this.NavigationBar.CurrentVisible = true;
                    isReset = true;
                }

                bool pre_status = this.NavigationBar.PrevButton_Rectangle.Contains(e.Location);
                if (this.NavigationBar.PrevButtonIsMouseEnter != pre_status)
                {
                    this.NavigationBar.PrevButtonIsMouseEnter = pre_status;
                    isReset = true;
                }
                bool next_status = this.NavigationBar.NextButton_Rectangle.Contains(e.Location);
                if (this.NavigationBar.NextButtonIsMouseEnter != next_status)
                {
                    this.NavigationBar.NextButtonIsMouseEnter = next_status;
                    isReset = true;
                }

                if (isReset)
                {
                    this.Invalidate();
                }
            }

            base.OnMouseMove(e);

        }

        protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
        {
            Size frameSize = new Size((int)Math.Ceiling(this.FrameSize.Width * this.ScaleDpi), (int)Math.Ceiling(this.FrameSize.Height * this.ScaleDpi));
            if (this.IsHorizonta(this.Orientation))
            {
                width = frameSize.Width * this.FrameAmount;
                height = frameSize.Height;
            }
            else
            {
                width = frameSize.Width;
                height = frameSize.Height * this.FrameAmount;
            }

            base.SetBoundsCore(x, y, width, height, specified);
        }

        protected override void OnResize(EventArgs e)
        {
            base.OnResize(e);

            this.InitializeElement();
            this.Invalidate();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                MainThreadAnimationControl.AnimationStop(this);
                if (this.imageFrames != null)
                {
                    for (int i = 0; i < this.imageFrames.Count; i++)
                    {
                        if (this.imageFrames[i].ScaleImage != null)
                        {
                            this.imageFrames[i].ScaleImage.Dispose();
                            this.imageFrames[i].ScaleImage = null;
                            this.imageFrames[i].SourceImageIndex = -1;
                        }
                    }
                }
            }
            base.Dispose(disposing);
        }

        /// <summary>
        /// 动画控件动画中要处理的内容(不能时耗时操作)
        /// </summary>
        /// <param name="interval">动画定时器间隔时间</param>
        protected override void Animationing(int interval)
        {
            if (this.animationStatus == AnimationStatus.Slide)
            {
                bool finish = false;
                this.slideTimeValue += interval;
                if (this.slideTimeValue > this.FrameSliderTime)
                {
                    this.slideTimeValue = this.FrameSliderTime;

                    finish = true;
                }

                double progress = 1.0 - Math.Pow(1.0 - this.slideTimeValue / this.FrameSliderTime, 2.0);//EaseOut 动画公式 
                if (finish)
                {
                    if (progress < 0)
                        progress = 0;
                    if (progress > 1)
                        progress = 1;

                    this.slideTimeValue = 0;
                    this.intervalTimeValue = 0;
                    this.current_distanceprogress = 1;

                    this.RestoreOrientation();
                    if (this.isOnceSlide)
                    {
                        this.Stop();
                        this.isOnceSlide = false;
                    }
                    else
                    {
                        this.animationStatus = AnimationStatus.Await;
                    }
                }

                this.current_distanceprogress = progress;
                this.Invalidate();
            }
            else if (this.animationStatus == AnimationStatus.Await)
            {
                if (this.isSuspendIntervalTimeValue)
                {
                    return;
                }

                this.intervalTimeValue += interval;
                if (this.intervalTimeValue >= this.FrameIntervalTime)
                {
                    this.SwitchNext();
                }
            }
        }

        #endregion

        #region 虚方法

        protected virtual void OnIndexChanged(EventArgs e)
        {
            EventHandler handler = Events[EventIndexChanged] as EventHandler;
            if (handler != null)
            {
                handler(this, e);
            }
        }

        #endregion

        #region 公开方法

        /// <summary>
        /// 开始播放
        /// </summary>
        public void Play()
        {
            this.isOnceSlide = false;
            if (this.animationStatus == AnimationStatus.Stop)
            {
                this.animationStatus = AnimationStatus.Await;
            }
            if (!this.isDisabled)
            {
                MainThreadAnimationControl.AnimationStart(this);
            }
        }

        /// <summary>
        /// 停止播放
        /// </summary>
        public void Stop()
        {
            this.isOnceSlide = false;
            this.slideTimeValue = 0;
            this.intervalTimeValue = 0;
            this.current_distanceprogress = 1;
            this.animationStatus = AnimationStatus.Stop;
            MainThreadAnimationControl.AnimationStop(this);
        }

        #endregion

        #region 公开方法

        /// <summary>
        /// 初始化控件内部元素布局
        /// </summary>
        public void InitializeElement()
        {
            this.InitializeNavigationBarRectangle();
            this.UpdateImageFrameInfo();
        }

        /// <summary>
        /// 初始化导航栏Rectangle
        /// </summary>
        internal void InitializeNavigationBarRectangle()
        {
            Size scale_navigationBarSize = new Size((int)Math.Ceiling(this.NavigationBar.ButtonSize.Width * this.ScaleDpi), (int)Math.Ceiling(this.NavigationBar.ButtonSize.Height * this.ScaleDpi));

            if (this.IsHorizonta(this.Orientation))
            {
                float barbtn_margin = scale_navigationBarSize.Width / 5f;
                this.NavigationBar.PrevButton_Rectangle = new RectangleF(this.ClientRectangle.X + barbtn_margin, this.ClientRectangle.Y + (this.ClientRectangle.Height - scale_navigationBarSize.Height) / 2f, scale_navigationBarSize.Width, scale_navigationBarSize.Height);
                this.NavigationBar.NextButton_Rectangle = new RectangleF(this.ClientRectangle.Right - scale_navigationBarSize.Width - barbtn_margin, this.ClientRectangle.Y + (this.ClientRectangle.Height - scale_navigationBarSize.Height) / 2f, scale_navigationBarSize.Width, scale_navigationBarSize.Height);
                float barbtn_avg_w = this.NavigationBar.PrevButton_Rectangle.Width / 4f;
                float barbtn_avg_h = this.NavigationBar.PrevButton_Rectangle.Height / 6f;

                PointF[] pre_line_points = new PointF[3];
                pre_line_points[0] = new PointF((this.NavigationBar.PrevButton_Rectangle.X + barbtn_avg_w * 3), (this.NavigationBar.PrevButton_Rectangle.Y + barbtn_avg_h));
                pre_line_points[1] = new PointF((this.NavigationBar.PrevButton_Rectangle.X + barbtn_avg_w), (this.NavigationBar.PrevButton_Rectangle.Y + barbtn_avg_h * 3));
                pre_line_points[2] = new PointF((this.NavigationBar.PrevButton_Rectangle.X + barbtn_avg_w * 3), (this.NavigationBar.PrevButton_Rectangle.Y + barbtn_avg_h * 5));
                this.NavigationBar.PrevButton_LinePoint = pre_line_points;

                PointF[] next_line_points = new PointF[3];
                next_line_points[0] = new PointF((this.NavigationBar.NextButton_Rectangle.Right - barbtn_avg_w * 3), (this.NavigationBar.NextButton_Rectangle.Y + barbtn_avg_h));
                next_line_points[1] = new PointF((this.NavigationBar.NextButton_Rectangle.Right - barbtn_avg_w), (this.NavigationBar.NextButton_Rectangle.Y + barbtn_avg_h * 3));
                next_line_points[2] = new PointF((this.NavigationBar.NextButton_Rectangle.Right - barbtn_avg_w * 3), (this.NavigationBar.NextButton_Rectangle.Y + barbtn_avg_h * 5));
                this.NavigationBar.NextButton_LinePoint = next_line_points;

            }
            else
            {
                float barbtn_margin = scale_navigationBarSize.Width / 5f;
                this.NavigationBar.PrevButton_Rectangle = new RectangleF(this.ClientRectangle.X + (this.ClientRectangle.Width - scale_navigationBarSize.Height) / 2f, this.ClientRectangle.Y + barbtn_margin, scale_navigationBarSize.Height, scale_navigationBarSize.Width);
                this.NavigationBar.NextButton_Rectangle = new RectangleF(this.ClientRectangle.X + (this.ClientRectangle.Width - scale_navigationBarSize.Height) / 2f, this.ClientRectangle.Bottom - scale_navigationBarSize.Width - barbtn_margin, scale_navigationBarSize.Height, scale_navigationBarSize.Width);
                float barbtn_avg_w = this.NavigationBar.PrevButton_Rectangle.Width / 6f;
                float barbtn_avg_h = this.NavigationBar.PrevButton_Rectangle.Height / 4f;

                PointF[] pre_line_points = new PointF[3];
                pre_line_points[0] = new PointF((this.NavigationBar.NextButton_Rectangle.X + barbtn_avg_w), (this.NavigationBar.NextButton_Rectangle.Bottom - barbtn_avg_h * 3));
                pre_line_points[1] = new PointF((this.NavigationBar.NextButton_Rectangle.X + barbtn_avg_w * 3), (this.NavigationBar.NextButton_Rectangle.Bottom - barbtn_avg_h));
                pre_line_points[2] = new PointF((this.NavigationBar.NextButton_Rectangle.X + barbtn_avg_w * 5), (this.NavigationBar.NextButton_Rectangle.Bottom - barbtn_avg_h * 3));
                this.NavigationBar.PrevButton_LinePoint = pre_line_points;

                PointF[] next_line_points = new PointF[3];
                next_line_points[0] = new PointF((this.NavigationBar.PrevButton_Rectangle.X + barbtn_avg_w), (this.NavigationBar.PrevButton_Rectangle.Y + barbtn_avg_h * 3));
                next_line_points[1] = new PointF((this.NavigationBar.PrevButton_Rectangle.X + barbtn_avg_w * 3), (this.NavigationBar.PrevButton_Rectangle.Y + barbtn_avg_h));
                next_line_points[2] = new PointF((this.NavigationBar.PrevButton_Rectangle.X + barbtn_avg_w * 5), (this.NavigationBar.PrevButton_Rectangle.Y + barbtn_avg_h * 3));
                this.NavigationBar.NextButton_LinePoint = next_line_points;

            }
        }

        /// <summary>
        /// 更新图片框信息 (当前显示区的开始图片的索引：负向第一个为最左边、正向第一个为最右边)
        /// </summary>
        internal void UpdateImageFrameInfo()
        {
            Size scale_frameSize = new Size((int)Math.Ceiling(this.FrameSize.Width * this.ScaleDpi), (int)Math.Ceiling(this.FrameSize.Height * this.ScaleDpi));

            if (this.IsNegative(this.Orientation))
            {
                for (int i = 0; i < this.imageFrames.Count; i++)
                {
                    int index_tmp = this.ValidImageIndex(this.Index - 1 + i);
                    if (index_tmp > -1)
                    {
                        this.imageFrames[i].SourceImageIndex = index_tmp;
                        this.imageFrames[i].ScaleImage = (this.Items[index_tmp].Image == null || scale_frameSize == this.Items[index_tmp].Image.Size) ? null : ControlHelper.ScaleImage(this.Items[index_tmp].Image, scale_frameSize);
                    }
                    else
                    {
                        this.imageFrames[i].SourceImageIndex = -1;
                        this.imageFrames[i].ScaleImage = null;
                    }
                }
            }
            else
            {
                for (int i = this.imageFrames.Count - 1; i >= 0; i--)
                {
                    int index_tmp = this.ValidImageIndex(this.Index - 1 + (this.imageFrames.Count - 1 - i));
                    if (index_tmp > -1)
                    {
                        this.imageFrames[i].SourceImageIndex = index_tmp;
                        this.imageFrames[i].ScaleImage = (this.Items[index_tmp].Image == null || scale_frameSize == this.Items[index_tmp].Image.Size) ? null : ControlHelper.ScaleImage(this.Items[index_tmp].Image, scale_frameSize);
                    }
                    else
                    {
                        this.imageFrames[i].SourceImageIndex = -1;
                        this.imageFrames[i].ScaleImage = null;
                    }
                }
            }
        }

        #endregion 

        #region 私有方法

        /// <summary>
        /// 加载图片框集合
        /// </summary>
        private void LoadImageFrame()
        {
            List<ImageFrame> tmp = this.imageFrames;
            List<ImageFrame> new_imageFrames = new List<ImageFrame>();
            for (int i = 0; i < this.FrameAmount + 2; i++)
            {
                new_imageFrames.Add(new ImageFrame());
            }
            this.imageFrames = new_imageFrames;

            for (int i = 0; i < tmp.Count; i++)
            {
                if (tmp[i].ScaleImage != null)
                {
                    tmp[i].ScaleImage.Dispose();
                }
            }
            tmp.Clear();
        }

        /// <summary>
        /// 根据滑动方向切换到下一个图片
        /// </summary>
        private void SwitchNext()
        {
            this.index = this.ValidImageIndex(this.Index + (this.IsNegative(this.Orientation) != this.IsNegative(this.current_orientation) ? -1 : 1));
            this.animationStatus = AnimationStatus.Slide;
            this.intervalTimeValue = 0;
            this.slideTimeValue = 0;
            this.current_distanceprogress = 1;

            this.UpdateImageFrameInfo();

            if (!this.DesignMode)
            {
                this.OnIndexChanged(EventArgs.Empty);
            }
        }

        /// <summary>
        /// 还原当前滑动方向到Orientation设置的滑动方向
        /// </summary>
        private void RestoreOrientation()
        {
            if (this.Orientation != this.current_orientation)
            {
                this.current_orientation = this.Orientation;
            }
        }

        /// <summary>
        /// 获取当前滑动方向的图片框滑动距离
        /// </summary>
        private int GetImageFrameSlideDirection()
        {
            switch (this.current_orientation)
            {
                case ImageSlideOrientation.BottomToTop:
                    {
                        return (int)Math.Ceiling(this.FrameSize.Height * this.ScaleDpi);
                    }
                case ImageSlideOrientation.TopToBottom:
                    {
                        return -(int)Math.Ceiling(this.FrameSize.Height * this.ScaleDpi);
                    }
                case ImageSlideOrientation.RightToLeft:
                    {
                        return (int)Math.Ceiling(this.FrameSize.Width * this.ScaleDpi);
                    }
                case ImageSlideOrientation.LeftToRight:
                    {
                        return -(int)Math.Ceiling(this.FrameSize.Width * this.ScaleDpi);
                    }
                default:
                    {
                        return 0;
                    }
            }
        }

        /// <summary>
        /// 根据控件失效状态自动更新控件动画
        /// </summary>
        private void AutoUpdateDisabledStatus()
        {
            if (!this.Enabled || !this.Visible || this.Parent == null)
            {
                if (this.isDisabled == false)
                {
                    this.isDisabled = true;
                }
            }
            else
            {
                this.isDisabled = false;
            }

            if (this.isDisabled)
            {
                MainThreadAnimationControl.AnimationStop(this);
                this.isOnceSlide = false;
                this.slideTimeValue = 0;
                this.intervalTimeValue = 0;
                this.current_distanceprogress = 1;

                this.RestoreOrientation();
                if (this.animationStatus == AnimationStatus.Await || this.animationStatus == AnimationStatus.Slide)
                {
                    this.animationStatus = AnimationStatus.Await;
                }
                this.Invalidate();
            }
            else
            {
                if (this.animationStatus == AnimationStatus.Await || this.animationStatus == AnimationStatus.Slide)
                {
                    this.slideTimeValue = 0;
                    this.intervalTimeValue = 0;
                    this.current_distanceprogress = 1;

                    this.RestoreOrientation();
                    this.animationStatus = AnimationStatus.Await;
                    this.Invalidate();
                    MainThreadAnimationControl.AnimationStart(this);
                }
            }
        }

        /// <summary>
        /// 设置默认图片索引
        /// </summary>
        internal void SetImageDefaultIndex()
        {
            if (this.Items.Count > 0)
            {
                if (this.index == -1)
                {
                    this.index = 0;
                }
            }
            else
            {
                this.index = -1;
            }
        }

        /// <summary>
        /// 验证图片索引
        /// </summary>
        /// <param name="index">图片索引</param>
        /// <returns></returns>
        private int ValidImageIndex(int index)
        {
            int count = this.Items.Count;

            if (count < 1)
                return -1;

            while (index >= count)
                index -= count;
            while (index < 0)
                index += count;
            return index;
        }

        /// <summary>
        /// 图片选项是否在图片框中
        /// </summary>
        /// <param name="item">图片选项</param>
        internal bool IsInImageFrame(ImageSlideItem item)
        {
            int index = this.Items.IndexOf(item);
            if (index > -1)
            {
                for (int i = 0; i < this.imageFrames.Count; i++)
                {
                    if (this.imageFrames[i].SourceImageIndex == index)
                    {
                        return true;
                    }
                }
            }
            return false;
        }

        /// <summary>
        /// 是否横向滑动（LeftToRight、RightToLeft）
        /// </summary>
        /// <param name="orientation"></param>
        /// <returns></returns>
        private bool IsHorizonta(ImageSlideOrientation orientation)
        {
            return (orientation == ImageSlideOrientation.LeftToRight || orientation == ImageSlideOrientation.RightToLeft);
        }

        /// <summary>
        /// 是否负方向滑动（RightToLeft、BottomToTop）
        /// </summary>
        /// <param name="orientation"></param>
        /// <returns></returns>
        internal bool IsNegative(ImageSlideOrientation orientation)
        {
            return (orientation == ImageSlideOrientation.RightToLeft || orientation == ImageSlideOrientation.BottomToTop);
        }

        #endregion

        #region 枚举

        /// <summary>
        /// 动画状态
        /// </summary>
        private enum AnimationStatus
        {
            /// <summary>
            /// 停止
            /// </summary>
            Stop,
            /// <summary>
            /// 间隔等待中
            /// </summary>
            Await,
            /// <summary>
            /// 滑动中
            /// </summary>
            Slide
        }

        #endregion

        #region 类

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class TitleBarObject
        {
            private ImageSlide owner = null;
            internal TitleBarObject(ImageSlide owner) { this.owner = owner; }

            #region 属性

            private bool visible = true;
            /// <summary>
            ///是否显示
            /// </summary>
            [Description("是否显示")]
            [PropertyOrder(-200)]
            [DefaultValue(true)]
            public bool Visible
            {
                get { return this.visible; }
                set
                {
                    if (this.visible == value)
                        return;

                    this.visible = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private TBPadding tBPadding = new TBPadding(4, 4);
            /// <summary>
            ///上下内边距
            /// </summary>
            [Description("上下内边距")]
            [PropertyOrder(-199)]
            [DefaultValue(typeof(TBPadding), "4,4")]
            public TBPadding TBPadding
            {
                get { return this.tBPadding; }
                set
                {
                    if (this.tBPadding == value)
                        return;

                    this.tBPadding = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            #endregion

        }

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class NavigationBarObject
        {
            private ImageSlide owner = null;
            internal NavigationBarObject(ImageSlide owner) { this.owner = owner; }

            #region 属性

            private ImageSlideNavigationBarVisibility visible = ImageSlideNavigationBarVisibility.Always;
            /// <summary>
            ///导航栏按钮显示方式
            /// </summary>
            [Description("导航栏按钮显示方式")]
            [PropertyOrder(-200)]
            [DefaultValue(ImageSlideNavigationBarVisibility.Always)]
            public ImageSlideNavigationBarVisibility Visible
            {
                get { return this.visible; }
                set
                {
                    if (this.visible == value)
                        return;

                    this.visible = value;
                    this.CurrentVisible = (this.Visible == ImageSlideNavigationBarVisibility.Always);
                    if (this.owner != null)
                    {
                        this.owner.InitializeNavigationBarRectangle();
                        this.owner.Invalidate();
                    }
                }
            }

            private Size buttonSize = new Size(25, 50);
            /// <summary>
            /// 按钮Size
            /// </summary>
            [Description("按钮Size")]
            [PropertyOrder(-198)]
            [DefaultValue(typeof(Size), "25, 50")]
            public Size ButtonSize
            {
                get { return this.buttonSize; }
                set
                {
                    if (value.Width < 1)
                    {
                        value.Width = 1;
                    }
                    if (value.Height < 1)
                    {
                        value.Height = 1;
                    }
                    if (this.buttonSize == value)
                        return;

                    this.buttonSize = value;
                    if (this.owner != null)
                    {
                        this.owner.InitializeNavigationBarRectangle();
                        this.owner.Invalidate();
                    }

                }
            }

            private int buttonLineThickness = 2;
            /// <summary>
            /// 按钮线条厚度
            /// </summary>
            [Description("按钮线条厚度")]
            [PropertyOrder(-196)]
            [DefaultValue(2)]
            public int ButtonLineThickness
            {
                get { return this.buttonLineThickness; }
                set
                {
                    if (this.buttonLineThickness == value || value <= 0)
                        return;

                    this.buttonLineThickness = value;
                    if (this.owner != null)
                    {
                        this.owner.InitializeNavigationBarRectangle();
                        this.owner.Invalidate();
                    }
                }
            }

            #endregion

            #region 临时存储

            /// <summary>
            /// 导航栏当前显示状态
            /// </summary>
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            internal bool CurrentVisible { get; set; }

            private object prevButton_Object = new object();
            /// <summary>
            /// 上一个按钮对象
            /// </summary>
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            internal object PrevButton_Object { get { return this.prevButton_Object; } }

            /// <summary>
            /// 上一个按钮rectf
            /// </summary>
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            internal RectangleF PrevButton_Rectangle { get; set; }

            /// <summary>
            /// 上一个按钮线条点集合
            /// </summary>
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            internal PointF[] PrevButton_LinePoint { get; set; }

            /// <summary>
            /// 鼠标是否已进入上一个按钮
            /// </summary>
            [DefaultValue(false)]
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            public bool PrevButtonIsMouseEnter { get; set; }

            private object nextButton_Object = new object();
            /// <summary>
            /// 下一个按钮对象
            /// </summary>
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            internal object NextButton_Object { get { return this.nextButton_Object; } }

            /// <summary>
            /// 下一个按钮rectf
            /// </summary>
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            internal RectangleF NextButton_Rectangle { get; set; }

            /// <summary>
            /// 下一个按钮线条点集合
            /// </summary>
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            internal PointF[] NextButton_LinePoint { get; set; }

            /// <summary>
            /// 鼠标是否已进入下一个按钮
            /// </summary>
            [DefaultValue(false)]
            [Browsable(false)]
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            public bool NextButtonIsMouseEnter { get; set; }

            #endregion

        }

        [TypeConverter(typeof(PropertyOrderConverter))]
        public class LegendsBarObject
        {
            private ImageSlide owner = null;
            internal LegendsBarObject(ImageSlide owner) { this.owner = owner; }

            #region 属性

            private bool visible = true;
            /// <summary>
            ///是否显示图例栏
            /// </summary>
            [Description("是否显示图例栏")]
            [PropertyOrder(-200)]
            [DefaultValue(true)]
            public bool Visible
            {
                get { return this.visible; }
                set
                {
                    if (this.visible == value)
                        return;

                    this.visible = value;
                    if (this.owner != null)
                    {
                        this.owner.Invalidate();
                    }
                }
            }

            private int size = 12;
            /// <summary>
            ///图例Size
            /// </summary>
            [Description("图例Size")]
            [PropertyOrder(-198)]
            [DefaultValue(12)]
            public int Size
            {
                get { return this.size; }
                set
                {
                    if (this.size == value || value <= 0)
                        return;

                    this.size = value;
                    if (this.Visible)
                    {
                        if (this.owner != null)
                        {
                            this.owner.Invalidate();
                        }
                    }
                }
            }

            #endregion

        }

        /// <summary>
        /// 图片框
        /// </summary>
        private class ImageFrame
        {
            private int sourceImageIndex = 0;
            /// <summary>
            /// 原图片索引
            /// </summary>
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            public int SourceImageIndex
            {
                get { return this.sourceImageIndex; }
                set { this.sourceImageIndex = value; }
            }

            private Image scaleImage = null;
            /// <summary>
            /// 缩放后图片
            /// </summary>
            [EditorBrowsable(EditorBrowsableState.Never)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
            public Image ScaleImage
            {
                get { return this.scaleImage; }
                set
                {
                    Image tmp = this.scaleImage;
                    this.scaleImage = value;
                    if (tmp != null)
                    {
                        tmp.Dispose();
                    }
                }
            }
        }

        #endregion

        #region 外观

        public class StyleAppearanceObject : AppearanceObjectBase
        {
            internal StyleAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

            #region 属性

            private Color skinBorderColor = Color.Empty;
            private readonly Color defaultBorderColor = SystemColors.ActiveCaption;
            private Color borderColor = Color.Empty;
            /// <summary>
            /// 边框颜色
            /// </summary>
            [Description("边框颜色")]
            [PropertyOrder(-159)]
            [SkinProperty(true, false)]
            public Color BorderColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore())
                    {
                        return this.skinBorderColor;
                    }

                    if (this.borderColor != Color.Empty)
                    {
                        return this.borderColor;
                    }

                    return this.defaultBorderColor;
                }
                set
                {
                    if (this.borderColor == value)
                        return;

                    this.borderColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeBorderColor()
            {
                return this.borderColor != Color.Empty;
            }
            private void ResetBorderColor()
            {
                this.borderColor = Color.Empty;
                this.Invalidate();
            }

            private Color skinBackColor = Color.Empty;
            private readonly Color defaultBackColor = SystemColors.Control;
            private Color backColor = Color.Empty;
            /// <summary>
            /// 背景颜色
            /// </summary>
            [Description("背景颜色")]
            [PropertyOrder(-195)]
            [SkinProperty(true, true)]
            public Color BackColor
            {
                get
                {
                    if (this.owner.GetSkinObjectSkinStateCore() && this.skinBackColor != Color.Empty)
                    {
                        return this.skinBackColor;
                    }

                    if (this.backColor != Color.Empty)
                    {
                        return this.backColor;
                    }

                    if (((Control)this.owner).Parent != null)
                    {
                        return ((Control)this.owner).Parent.BackColor;
                    }

                    return this.defaultBackColor;
                }
                set
                {
                    if (this.backColor == value)
                        return;

                    this.backColor = value;
                    this.Invalidate();
                }
            }
            private bool ShouldSerializeBackColor()
            {
                return this.backColor != Color.Empty;
            }
            private void ResetBackColor()
            {
                this.backColor = Color.Empty;
                this.Invalidate();
            }

            private TitleBarAppearanceObject titleBar;
            /// <summary>
            /// 标题栏
            /// </summary>
            [Description("标题栏")]
            [PropertyOrder(-194)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public TitleBarAppearanceObject TitleBar
            {
                get
                {
                    if (this.titleBar == null)
                        this.titleBar = new TitleBarAppearanceObject(this.owner, this);
                    return this.titleBar;
                }
            }

            private NavigationBarAppearanceObject navigationBar;
            /// <summary>
            /// 导航栏
            /// </summary>
            [Description("导航栏")]
            [PropertyOrder(-192)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public NavigationBarAppearanceObject NavigationBar
            {
                get
                {
                    if (this.navigationBar == null)
                        this.navigationBar = new NavigationBarAppearanceObject(this.owner, this);
                    return this.navigationBar;
                }
            }

            private LegendsBarAppearanceObject legendsBar;
            /// <summary>
            /// 图例栏
            /// </summary>
            [Description("图例栏")]
            [PropertyOrder(-190)]
            [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
            [SkinProperty(true, false)]
            public LegendsBarAppearanceObject LegendsBar
            {
                get
                {
                    if (this.legendsBar == null)
                        this.legendsBar = new LegendsBarAppearanceObject(this.owner, this);
                    return this.legendsBar;
                }
            }

            #endregion

            public class TitleBarAppearanceObject : AppearanceObjectBase
            {
                internal TitleBarAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private Color skinBorderColor = Color.Empty;
                private readonly Color defaultBorderColor = Color.FromArgb(130, 128, 128, 128);
                private Color borderColor = Color.Empty;
                /// <summary>
                /// 边框颜色
                /// </summary>
                [Description("边框颜色")]
                [PropertyOrder(-159)]
                [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                [SkinProperty(true, false)]
                public Color BorderColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBorderColor;
                        }

                        if (this.borderColor != Color.Empty)
                        {
                            return this.borderColor;
                        }

                        return this.defaultBorderColor;
                    }
                    set
                    {
                        if (this.borderColor == value)
                            return;

                        this.borderColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBorderColor()
                {
                    return this.borderColor != Color.Empty;
                }
                private void ResetBorderColor()
                {
                    this.borderColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinBackColor = Color.Empty;
                private readonly Color defaultBackColor = Color.FromArgb(100, 128, 128, 128);
                private Color backColor = Color.Empty;
                /// <summary>
                /// 背景颜色
                /// </summary>
                [Description("背景颜色")]
                [PropertyOrder(-158)]
                [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                [SkinProperty(true, false)]
                public Color BackColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinBackColor;
                        }

                        if (this.backColor != Color.Empty)
                        {
                            return this.backColor;
                        }

                        return this.defaultBackColor;
                    }
                    set
                    {
                        if (this.backColor == value)
                            return;

                        this.backColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeBackColor()
                {
                    return this.backColor != Color.Empty;
                }
                private void ResetBackColor()
                {
                    this.backColor = Color.Empty;
                    this.Invalidate();
                }

                private Color skinTextColor = Color.Empty;
                private readonly Color defaultTextColor = Color.White;
                private Color textColor = Color.Empty;
                /// <summary>
                /// 文本颜色
                /// </summary>
                [Description("文本颜色")]
                [PropertyOrder(-157)]
                [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                [SkinProperty(true, false)]
                public Color TextColor
                {
                    get
                    {
                        if (this.owner.GetSkinObjectSkinStateCore())
                        {
                            return this.skinTextColor;
                        }

                        if (this.textColor != Color.Empty)
                        {
                            return this.textColor;
                        }

                        return this.defaultTextColor;
                    }
                    set
                    {
                        if (this.textColor == value)
                            return;

                        this.textColor = value;
                        this.Invalidate();
                    }
                }
                private bool ShouldSerializeTextColor()
                {
                    return this.textColor != Color.Empty;
                }
                private void ResetTextColor()
                {
                    this.textColor = Color.Empty;
                    this.Invalidate();
                }

                #endregion

            }

            public class NavigationBarAppearanceObject : AppearanceObjectBase
            {
                internal NavigationBarAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private ItemAppearanceObject normal;
                /// <summary>
                /// 正常状态
                /// </summary>
                [Description("正常状态")]
                [PropertyOrder(-194)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemAppearanceObject Normal
                {
                    get
                    {
                        if (this.normal == null)
                            this.normal = new ItemAppearanceObject(this.owner, this, Color.FromArgb(120, 128, 128, 128), Color.FromArgb(100, 128, 128, 128), Color.FromArgb(200, 255, 255, 255));
                        return this.normal;
                    }
                }

                private ItemAppearanceObject enter;
                /// <summary>
                /// 鼠标进入状态
                /// </summary>
                [Description("鼠标进入状态")]
                [PropertyOrder(-192)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemAppearanceObject Enter
                {
                    get
                    {
                        if (this.enter == null)
                            this.enter = new ItemAppearanceObject(this.owner, this, Color.FromArgb(120, 128, 128, 128), Color.FromArgb(200, 128, 128, 128), Color.FromArgb(200, 255, 255, 255));
                        return this.enter;
                    }
                }

                #endregion

                public class ItemAppearanceObject : AppearanceObjectBase
                {
                    internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color borderColor, Color backColor, Color foreColor) : base(owner, parent)
                    {
                        this.defaultBorderColor = borderColor;
                        this.defaultBackColor = backColor;
                        this.defaultForeColor = foreColor;
                    }

                    #region 属性

                    private Color skinBorderColor = Color.Empty;
                    private readonly Color defaultBorderColor = Color.Empty;
                    private Color borderColor = Color.Empty;
                    /// <summary>
                    /// 边框颜色
                    /// </summary>
                    [Description("边框颜色")]
                    [PropertyOrder(-159)]
                    [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                    [SkinProperty(true, false)]
                    public Color BorderColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinBorderColor;
                            }

                            if (this.borderColor != Color.Empty)
                            {
                                return this.borderColor;
                            }

                            return this.defaultBorderColor;
                        }
                        set
                        {
                            if (this.borderColor == value)
                                return;

                            this.borderColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeBorderColor()
                    {
                        return this.borderColor != Color.Empty;
                    }
                    private void ResetBorderColor()
                    {
                        this.borderColor = Color.Empty;
                        this.Invalidate();
                    }

                    private Color skinBackColor = Color.Empty;
                    private readonly Color defaultBackColor = Color.Empty;
                    private Color backColor = Color.Empty;
                    /// <summary>
                    /// 背景颜色
                    /// </summary>
                    [Description("背景颜色")]
                    [PropertyOrder(-158)]
                    [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                    [SkinProperty(true, false)]
                    public Color BackColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinBackColor;
                            }

                            if (this.backColor != Color.Empty)
                            {
                                return this.backColor;
                            }

                            return this.defaultBackColor;
                        }
                        set
                        {
                            if (this.backColor == value)
                                return;

                            this.backColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeBackColor()
                    {
                        return this.backColor != Color.Empty;
                    }
                    private void ResetBackColor()
                    {
                        this.backColor = Color.Empty;
                        this.Invalidate();
                    }

                    private Color skinForeColor = Color.Empty;
                    private Color defaultForeColor = Color.Empty;
                    private Color foreColor = Color.Empty;
                    /// <summary>
                    /// 前景颜色
                    /// </summary>
                    [Description("前景颜色")]
                    [PropertyOrder(-157)]
                    [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                    [SkinProperty(true, false)]
                    public Color ForeColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinForeColor;
                            }

                            if (this.foreColor != Color.Empty)
                            {
                                return this.foreColor;
                            }

                            return this.defaultForeColor;
                        }
                        set
                        {
                            if (this.foreColor == value)
                                return;

                            this.foreColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeForeColor()
                    {
                        return this.foreColor != Color.Empty;
                    }
                    private void ResetForeColor()
                    {
                        this.foreColor = Color.Empty;
                        this.Invalidate();
                    }

                    #endregion

                }

            }

            public class LegendsBarAppearanceObject : AppearanceObjectBase
            {
                internal LegendsBarAppearanceObject(ISkinObject owner, AppearanceObjectBase parent) : base(owner, parent) { }

                #region 属性

                private ItemAppearanceObject normal;
                /// <summary>
                /// 正常状态
                /// </summary>
                [Description("正常状态")]
                [PropertyOrder(-194)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemAppearanceObject Normal
                {
                    get
                    {
                        if (this.normal == null)
                            this.normal = new ItemAppearanceObject(this.owner, this, Color.FromArgb(180, 128, 128, 128), Color.FromArgb(10, 128, 128, 128));
                        return this.normal;
                    }
                }

                private ItemAppearanceObject current;
                /// <summary>
                /// 当前选中状态
                /// </summary>
                [Description("当前选中状态")]
                [PropertyOrder(-192)]
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
                [SkinProperty(true, false)]
                public ItemAppearanceObject Current
                {
                    get
                    {
                        if (this.current == null)
                            this.current = new ItemAppearanceObject(this.owner, this, Color.FromArgb(180, 128, 128, 128), Color.FromArgb(100, 128, 128, 128));
                        return this.current;
                    }
                }

                #endregion

                public class ItemAppearanceObject : AppearanceObjectBase
                {
                    internal ItemAppearanceObject(ISkinObject owner, AppearanceObjectBase parent, Color borderColor, Color backColor) : base(owner, parent)
                    {
                        this.defaultBorderColor = borderColor;
                        this.defaultBackColor = backColor;
                    }

                    #region 属性

                    private Color skinBorderColor = Color.Empty;
                    private readonly Color defaultBorderColor = Color.Empty;
                    private Color borderColor = Color.Empty;
                    /// <summary>
                    /// 边框颜色
                    /// </summary>
                    [Description("边框颜色")]
                    [PropertyOrder(-159)]
                    [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                    [SkinProperty(true, false)]
                    public Color BorderColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinBorderColor;
                            }

                            if (this.borderColor != Color.Empty)
                            {
                                return this.borderColor;
                            }

                            return this.defaultBorderColor;
                        }
                        set
                        {
                            if (this.borderColor == value)
                                return;

                            this.borderColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeBorderColor()
                    {
                        return this.borderColor != Color.Empty;
                    }
                    private void ResetBorderColor()
                    {
                        this.borderColor = Color.Empty;
                        this.Invalidate();
                    }

                    private Color skinBackColor = Color.Empty;
                    private readonly Color defaultBackColor = Color.Empty;
                    private Color backColor = Color.Empty;
                    /// <summary>
                    /// 背景颜色
                    /// </summary>
                    [Description("背景颜色")]
                    [PropertyOrder(-158)]
                    [Editor(typeof(AlphaColorEditor), typeof(UITypeEditor))]
                    [SkinProperty(true, false)]
                    public Color BackColor
                    {
                        get
                        {
                            if (this.owner.GetSkinObjectSkinStateCore())
                            {
                                return this.skinBackColor;
                            }

                            if (this.backColor != Color.Empty)
                            {
                                return this.backColor;
                            }

                            return this.defaultBackColor;
                        }
                        set
                        {
                            if (this.backColor == value)
                                return;

                            this.backColor = value;
                            this.Invalidate();
                        }
                    }
                    private bool ShouldSerializeBackColor()
                    {
                        return this.backColor != Color.Empty;
                    }
                    private void ResetBackColor()
                    {
                        this.backColor = Color.Empty;
                        this.Invalidate();
                    }

                    #endregion

                }

            }

        }

        #endregion

    }

}
